<?php
include("../myzhuaqu.php");
require_once('../vendor/autoload.php');


$sourceData=get2lm(0,0,"");

function rk($data,$pid){
    $data["pid"]=$pid;
    $data["status"]=1;
    insertupdate("jipu.jipu_item_category_shopee",$data,"select id from jipu.jipu_item_category_shopee where name='{$data['name']}' and id='{$data['id']}'");
}

function get2lm($cid,$pid,$trees){
    $cid=$cid==0?0:"\"{$cid}\"";
    $poststr="{\"catIds\":[{$cid}]}";
    $len=strlen($poststr);
    $http2=<<<TEXT2
GET https://seller.shopee.cn/api/v3/mtsku/get_mtsku_category_tree?SPC_CDS=949d75d9-8245-4567-916f-e54a6c336870&SPC_CDS_VER=2&include_level=3&cnsc_shop_id=1037607973&cbsc_shop_region=tw HTTP/1.1
Host: seller.shopee.cn
Connection: keep-alive
sec-ch-ua: "Not.A/Brand";v="8", "Chromium";v="114", "Google Chrome";v="114"
sc-fe-ver: 22.48597
locale: zh-CN
sc-fe-session: E630BE9AD0744B70
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36
sec-ch-ua-mobile: ?0
Accept: application/json, text/plain, */*
sec-ch-ua-platform: "Windows"
Sec-Fetch-Site: same-origin
Sec-Fetch-Mode: cors
Sec-Fetch-Dest: empty
Referer: https://seller.shopee.cn/portal/product/mtsku/new?cnsc_shop_id=1037607973
Accept-Encoding: gzip, deflate, br
Accept-Language: zh-CN,zh;q=0.9
Cookie: REC_T_ID=31022ae5-11aa-11ef-8175-96b763df3ddd; SPC_R_T_ID=ubb/SvkUKoaZm3IUcDmX98+Q01KMTvTTEpe1rWnGX/ztJyPpXW3nNbxS4Q0pmbmu00Yv92A5zqxvwtdjbdewV4hIwgNjLPitAYTL6rmiFZz8fK69xm28sk/GdAx0flhV7n84PUXxXNg96DEDrKkm0Yg+A5JM7ocDKNEHouIWnFQ=; SPC_R_T_IV=SE9jRExiblRRdVVhUGgyWg==; SPC_T_ID=ubb/SvkUKoaZm3IUcDmX98+Q01KMTvTTEpe1rWnGX/ztJyPpXW3nNbxS4Q0pmbmu00Yv92A5zqxvwtdjbdewV4hIwgNjLPitAYTL6rmiFZz8fK69xm28sk/GdAx0flhV7n84PUXxXNg96DEDrKkm0Yg+A5JM7ocDKNEHouIWnFQ=; SPC_T_IV=SE9jRExiblRRdVVhUGgyWg==; SPC_F=7S4T7Ec4FTN21nXNK5fdj4YVzf7BtXkz; REC7iLP4Q=83a00a88-7a49-441b-9cc8-1108be6e36d5; SPC_SI=stiLZQAAAABRS2NpUWRwZHmwyQIAAAAAa2R6T2VuUGE=; SPC_CNSC_SESSION=cf5c2525b115d94c759626aa6f91f38c_2_1904060; SPC_SC_OFFLINE_TOKEN=eyJkYXRhIjoieUd4emNtU1Q4NGR5SU40dlBwbVc0WVNtU25oczhxLzBORDZ1VVM4TVdQcm1zQTl5cHBzcEIrS0NoSDV4V1JiUnE5dSsyNjgrSHN6WDluMFJIckxqWkF4R00zalY4WDhhdSs5MjNNNloreWtzcHkwOXVKQUZYZWZLeDBZMzRvUVNuanl0VmE5cTVpRjJVREJTSnpRZ1NnPT0iLCJpdiI6Ink4dXdsVC90M0JKUkFWazVSMlNTUVE9PSIsInNpZ24iOiJqa055VUsxNWY2Z0NJTW4vZUhtRklBc1o5YU4zbzJYMlIvbkY0czB2bFBXRmZ0TVBvWURxQTVJT2RNeXJ6enJOdW9lQ3JWeHhKRE9BQ08rR3paUE1CQT09In0=; SPC_CNSC_TK=02c8eb2668af406932e1c3204ece5aef; SPC_CNSC_UD=1_1904060; CNSC_SSO=cWI0aWtkMkhsMTlLTk5aU949AvfT5KzRFRDNrr+WlWgMUug5lQLA5WNl2zJKOBCK; _QPWSDCXHZQA=72042b15-bbb2-4ec2-97df-fb0deb4e1a31; SPC_CDS=949d75d9-8245-4567-916f-e54a6c336870; SPC_CDS_CHAT=f5f11f6b-583b-4c53-b7bc-ee0064584606; shopee_webUnique_ccd=LWu3oAbYNnravL3D7Enyug%3D%3D%7CkE2Fml2LxmjVYJj6vgvkctqfKfN9NL95tLOj8EHA7MYsT63sbQNyIhhAIuBZ8krtu9s4V%2FtrUoIy81Odjg%3D%3D%7CfMUOuX3If%2B0FBMeY%7C08%7C3; ds=2321ff2b47d1026502de59557d517888
Pragma: no-cache



TEXT2;

    $json=curlpost($http2);
    $sourceData=json_decode($json,1);
    $data=array();
    if(!empty($sourceData['data']["list"])) {
        for ($i = 0; $i < count($sourceData['data']["list"]); $i++) {
            $temp2 = array();
            $temp2["id"] = $sourceData['data']["list"][$i]["id"];
            $temp2["name"] = $sourceData['data']["list"][$i]["display_name"];
            $temp2["trees"] = $trees . $temp2["id"] . ",";
            rk($temp2, $pid);
            if (!$sourceData['data']["list"][$i]["is_prohibit"]) {
                getarr2lm($sourceData['data']["list"][$i]["children"], $sourceData['data']["list"][$i]["id"], $temp2["trees"]);
            }
        }
    }
}

function getarr2lm($arr,$pid,$trees){
    for ($i = 0; $i < count($arr); $i++) {
        $temp2 = array();
        $temp2["id"] = $arr[$i]["id"];
        $temp2["name"] = $arr[$i]["display_name"];
        $temp2["trees"] = $trees . $temp2["id"] . ",";
        rk($temp2, $pid);
        if (!$arr[$i]["is_prohibit"]) {
            getarr2lm($arr[$i]["children"], $arr[$i]["id"], $temp2["trees"]);
        }
        if ($arr[$i]["has_children"]&&count($arr[$i]["children"])==0) {
            $http='GET https://seller.shopee.cn/api/v3/mtsku/get_mtsku_category_list/?parent_cat_id='.$arr[$i]["id"].'&include_level=1 HTTP/1.1
Host: seller.shopee.cn
Connection: keep-alive
Cache-Control: max-age=0
sec-ch-ua: "Not.A/Brand";v="8", "Chromium";v="114", "Google Chrome";v="114"
sec-ch-ua-mobile: ?0
sec-ch-ua-platform: "Windows"
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7
Sec-Fetch-Site: none
Sec-Fetch-Mode: navigate
Sec-Fetch-User: ?1
Sec-Fetch-Dest: document
Accept-Encoding: gzip, deflate, br
Accept-Language: zh-CN,zh;q=0.9
Cookie: REC_T_ID=31022ae5-11aa-11ef-8175-96b763df3ddd; SPC_R_T_ID=ubb/SvkUKoaZm3IUcDmX98+Q01KMTvTTEpe1rWnGX/ztJyPpXW3nNbxS4Q0pmbmu00Yv92A5zqxvwtdjbdewV4hIwgNjLPitAYTL6rmiFZz8fK69xm28sk/GdAx0flhV7n84PUXxXNg96DEDrKkm0Yg+A5JM7ocDKNEHouIWnFQ=; SPC_R_T_IV=SE9jRExiblRRdVVhUGgyWg==; SPC_T_ID=ubb/SvkUKoaZm3IUcDmX98+Q01KMTvTTEpe1rWnGX/ztJyPpXW3nNbxS4Q0pmbmu00Yv92A5zqxvwtdjbdewV4hIwgNjLPitAYTL6rmiFZz8fK69xm28sk/GdAx0flhV7n84PUXxXNg96DEDrKkm0Yg+A5JM7ocDKNEHouIWnFQ=; SPC_T_IV=SE9jRExiblRRdVVhUGgyWg==; SPC_F=7S4T7Ec4FTN21nXNK5fdj4YVzf7BtXkz; REC7iLP4Q=83a00a88-7a49-441b-9cc8-1108be6e36d5; SPC_SI=stiLZQAAAABRS2NpUWRwZHmwyQIAAAAAa2R6T2VuUGE=; SPC_CNSC_SESSION=cf5c2525b115d94c759626aa6f91f38c_2_1904060; SPC_SC_OFFLINE_TOKEN=eyJkYXRhIjoieUd4emNtU1Q4NGR5SU40dlBwbVc0WVNtU25oczhxLzBORDZ1VVM4TVdQcm1zQTl5cHBzcEIrS0NoSDV4V1JiUnE5dSsyNjgrSHN6WDluMFJIckxqWkF4R00zalY4WDhhdSs5MjNNNloreWtzcHkwOXVKQUZYZWZLeDBZMzRvUVNuanl0VmE5cTVpRjJVREJTSnpRZ1NnPT0iLCJpdiI6Ink4dXdsVC90M0JKUkFWazVSMlNTUVE9PSIsInNpZ24iOiJqa055VUsxNWY2Z0NJTW4vZUhtRklBc1o5YU4zbzJYMlIvbkY0czB2bFBXRmZ0TVBvWURxQTVJT2RNeXJ6enJOdW9lQ3JWeHhKRE9BQ08rR3paUE1CQT09In0=; SPC_CNSC_TK=02c8eb2668af406932e1c3204ece5aef; SPC_CNSC_UD=1_1904060; CNSC_SSO=cWI0aWtkMkhsMTlLTk5aU949AvfT5KzRFRDNrr+WlWgMUug5lQLA5WNl2zJKOBCK; _QPWSDCXHZQA=72042b15-bbb2-4ec2-97df-fb0deb4e1a31; SPC_CDS=f63211e9-722b-4078-8b2b-7fa3f56069dd; SPC_CDS_CHAT=33f0d868-c097-4ac6-bdac-c5ac8c157baa; shopee_webUnique_ccd=2H7nPDpQWHf5mqT%2F7A3wwQ%3D%3D%7Crk2Fml2LxmjVYJj6vgvkctqfKfN9NL95tLOj8FGbfMAsT63sbQNyIhhAIuBZ8krtu9s4V%2FtrUoIy81Odjg%3D%3D%7CfMUOuX3If%2B0FBMeY%7C08%7C3; ds=8e125926910bd9b2862bb66267ce92d0

';
            $json=curlpost($http);
            $data=json_decode($json,1);
            for ($j = 0; $j < count($data["data"]["list"][0]["category_list"]); $j++) {
                if($data["data"]["list"][0]["category_list"][$j]["id"]==$arr[$i]["id"]) continue;
                $temp3 = array();
                $temp3["id"] = $data["data"]["list"][0]["category_list"][$j]["id"];
                $temp3["name"] = $data["data"]["list"][0]["category_list"][$j]["display_name"];
                $temp3["trees"] = $trees . $temp2["id"] . "," . $temp3["id"] . ",";
                rk($temp3, $arr[$i]["id"]);
            }
        }
    }
}

//https://seller.shopee.cn/api/v3/mtsku/get_mtsku_category_list/?parent_cat_id=100848&include_level=1